use warnings;
use Test::More tests => '50';
use Inline C;

is(init_t(), 0, 'initialize the mac indir queue');
is(alloc_addr64_t(12345, 2), 0, 'allocate a indir entry for address 12345');
is(find_addr64_t(12345), 0, 'find the entry of 12345 in indir entry');
is(find_addr64_t(123456), -1, 'no entry of 123456 exists in indir entry');
is(find_addr16_t(15), -1, 'cannot find the entry of 15 in indir entry');
is(free_t(1), -1, 'no such entry whose dsn is 1 exists');
is(find_addr16_t(15), -1, 'cannot find the entry of 15 in indir entry');


is(alloc_addr16_t(20, 1), 0, 'allocate a indir entry for address 20');
is(alloc_addr16_t(21, 2), 0, 'allocate a indir entry for address 21');
is(alloc_addr16_t(22, 3), 0, 'allocate a indir entry for address 22');
is(alloc_addr16_t(23, 4), 0, 'allocate a indir entry for address 23');
is(alloc_addr16_t(24, 5), 0, 'allocate a indir entry for address 24');
is(alloc_addr16_t(25, 6), 0, 'allocate a indir entry for address 25');
is(alloc_addr16_t(26, 7), 0, 'allocate a indir entry for address 26');
is(alloc_addr16_t(27, 8), 0, 'allocate a indir entry for address 27');
is(alloc_addr16_t(28, 9), 0, 'allocate a indir entry for address 28');
is(alloc_addr16_t(29, 10), -1, 'indir is full, cannot allocate a indir entry for address 29');
is(alloc_addr16_t(30, 11), -1, 'indir is full, cannot allocate a indir entry for address 30');

is(free_t(1), 0, 'free indir entry whose dsn is 1');
is(free_t(2), 0, 'free indir entry whose dsn is 2');
is(free_t(3), 0, 'free indir entry whose dsn is 3');
is(free_t(4), 0, 'free indir entry whose dsn is 4');
is(free_t(5), 0, 'free indir entry whose dsn is 5');
is(free_t(6), 0, 'free indir entry whose dsn is 6');
is(free_t(7), 0, 'free indir entry whose dsn is 7');
is(free_t(8), 0, 'free indir entry whose dsn is 8');
is(free_t(9), 0, 'free indir entry whose dsn is 9');
is(free_t(10), -1, 'no indir entry whose entry is 10');
is(free_t(2), 0, 'free indir entry whose dsn is 2');

is(alloc_addr16_t(20, 0), 0, 'allocate a indir entry for address 20');
is(alloc_addr16_t(21, 1), 0, 'allocate a indir entry for address 21');
is(alloc_addr16_t(22, 2), 0, 'allocate a indir entry for address 22');
is(alloc_addr16_t(23, 3), 0, 'allocate a indir entry for address 23');
is(alloc_addr16_t(24, 4), 0, 'allocate a indir entry for address 24');
is(alloc_addr16_t(25, 5), 0, 'allocate a indir entry for address 25');
is(alloc_addr16_t(26, 6), 0, 'allocate a indir entry for address 26');
is(alloc_addr16_t(27, 7), 0, 'allocate a indir entry for address 27');
is(alloc_addr16_t(28, 8), 0, 'allocate a indir entry for address 28');
is(alloc_addr16_t(29, 9), 0, 'allocate a indir entry for address 29');

is(free_t(0), 0, 'free indir entry whose dsn is 0');
is(free_t(1), 0, 'free indir entry whose dsn is 1');
is(free_t(2), 0, 'free indir entry whose dsn is 2');
is(free_t(3), 0, 'free indir entry whose dsn is 3');
is(free_t(4), 0, 'free indir entry whose dsn is 4');
is(free_t(5), 0, 'free indir entry whose dsn is 5');
is(free_t(6), 0, 'free indir entry whose dsn is 6');
is(free_t(7), 0, 'free indir entry whose dsn is 7');
is(free_t(8), 0, 'free indir entry whose dsn is 8');
is(free_t(9), 0, 'free indir entry whose dsn is 9');
is(free_t(9), -1, 'no indir entry whose entry is 9');

__END__
__C__

#include "../../../../mac/mac.h"

#include "../../../../mac/list.c"
#include "../../../../mac/mem.c"
#include "../../../../mac/mac_info.c"
#include "mac_indir_test.c"
#include "../../../../mac/mac_indir.c"
#include "../../stub/timer_stub.c"

int init_t()
{
    unsigned char r;

    r = init();

    return r;
}

int alloc_addr64_t(unsigned long addr, unsigned char dsn)
{
    uint64 addr64 = addr;

    return alloc_addr64(addr64, dsn);     
}

int alloc_addr16_t(unsigned short addr, unsigned char dsn)
{
    return alloc_addr16(addr, dsn);     
}

int free_t(unsigned char dsn)
{
    return _free(dsn);
}

int find_addr64_t(unsigned long addr)
{
    uint64 addr64 = addr;

    return find_addr64(addr64);
}

int find_addr16_t(unsigned short addr)
{
    return find_addr16(addr);
}


